<!DOCTYPE html>
<!--suppress ThymeleafVariablesResolveInspection -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="layui-input-inline" style="margin-left: 26px">
    <select name="community_id" id="community_id" lay-verify="" lay-search>
    </select>
</div>

<input type="button" onclick="statusInit(1)" value="更新1"/>&nbsp;&nbsp;<input type="button" onclick="statusInit(2)" value="更新2"/>

</body>
<script src="../js/layui-v2.7.6/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="../js/layui-v2.7.6/layui/css/layui.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
    function  statusInit(community_id){
        console.log(community_id);
        $.ajax({
            type:"GET",//请求类型
            url:"../community/find",//请求的urlqh
            dataType:"json",//ajax接口（请求url）返回的数据类型
            success:function(data){//data：返回数据（json对象）
                var options="<option value='0'>请选择所属小区</option>";
                $("#community_id").html("");
                layui.form.render("select");
                for(var i = 0; i < data.data.length; i++) {
                    if (community_id==data.data[i].id) {
                        options += "<option selected value=\"" + data.data[i].id + "\" class>" + data.data[i].name + "</option>";
                    }else{
                        options += "<option value=\"" + data.data[i].id + "\" class>" + data.data[i].name + "</option>";
                    }
                }
                $("#community_id").append(options);
                layui.form.render("select");
            },
            error:function(data){//当访问时候，404，500 等非200的错误状态码
                alert("所属加载小区失败！");
            }
        });
    }

    getCommunity_id();
    function  getCommunity_id(){
        $.ajax({
            type:"GET",//请求类型
            url:"../community/find",//请求的urlqh
            dataType:"json",//ajax接口（请求url）返回的数据类型
            success:function(data){//data：返回数据（json对象）
                var options="<option value='0'>请选择所属小区</option>";
                $("#community_id").html("");
                layui.form.render("select");
                for(var i = 0; i < data.data.length; i++) {
                        options += "<option value=\"" + data.data[i].id + "\" class>" + data.data[i].name + "</option>";
                }
                $("#community_id").append(options);
                layui.form.render("select");
            },
            error:function(data){//当访问时候，404，500 等非200的错误状态码
                alert("所属加载小区失败！");
            }
        });
    }

</script>
</html>